package fr.uniscol.dao.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import fr.uniscol.dao.IGeographieDao;
import fr.uniscol.model.EtablissementModel;

public class EtablissementRowMapper implements RowMapper<EtablissementModel> {

	private IGeographieDao geoDao;

	public EtablissementRowMapper(IGeographieDao geoDao){
		this.geoDao = geoDao;
	}
	
	@Override
	public EtablissementModel mapRow(ResultSet rs, int line)
	throws SQLException {
		
		EtablissementModel etab = new EtablissementModel(rs.getInt("ETABLISSEMENTID"));
		etab.setUai(rs.getString("UAI"));
		etab.setNom(rs.getString("NOM"));
		etab.getAdresse().setAdresse1(rs.getString("ADRESSE1"));
		etab.getAdresse().setAdresse2(rs.getString("ADRESSE2"));
		etab.getAdresse().setAdresse3(rs.getString("ADRESSE3"));
		etab.getAdresse().setCodePostal(rs.getString("CP"));
		etab.getAdresse().setBoitePostale(rs.getString("BP"));
		etab.setTelephone(rs.getString("TELEPHONE"));
		etab.setEmail(rs.getString("EMAIL"));
		
		/*if(rs.getString("PAYSID") != null){
			etab.getAdresse().setPays(geoDao.getPaysById(rs.getInt("PAYSID")));
		}
		if(rs.getString("ACADEMIEID") != null){
			etab.setAcademie(geoDao.getAcademieById(rs.getInt("ACADEMIEID")));
		}
		if(rs.getString("DEPARTEMENTID") != null){
			etab.getAdresse().setDepartement(geoDao.getDepartementById(rs.getInt("DEPARTEMENTID")));
		}
		if(rs.getString("COMMUNEID") != null){
			etab.getAdresse().setCommune(geoDao.getCommuneById(rs.getInt("COMMUNEID")));
		}*/
		
		return etab;
	}
}
